import pandas as pd
import requests

class Opera():
    def __init__(self, filename, sheet_index=0):
        self.df = pd.read_excel(filename, sheet_name=sheet_index)
        self.filename = filename

    def get_case_data(self):
        data_list = []
        df2 = self.df.iloc[:, [3, 4, 5, 6, 7]]
        df2.columns = ['url', 'keys', 'data', 'method', 'status_code']
        for i in df2.index:
            data = df2.iloc[i].to_dict()
            data_list.append(data)
        return data_list

    def save_data(self,column,value):
        self.df[column] = value
        self.df.to_excel(self.filename,index=None)

def maoyan_requests(url,method,keys,data):
    if method.upper() == 'GET':
        res = requests.get(url,params=data)
    elif method.upper() == 'POST':
        if keys.lower() == 'data':
            res = requests.post(url,data=data)
        else:
            res = requests.post(url,json=data)
    elif method.upper() == 'PUT':
        res = requests.put(url,data=data)
    elif method.upper() == 'PATCH':
        res = requests.patch(url,data=data)
    elif method.upper() == 'DELETE':
        res = requests.delete(url)
    else:
        raise TypeError(f'{method}AGB')
    return res





